package com.qq.Servlet.Book;

import com.qq.util.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
//center过滤器的注解
@WebServlet("/center/book/del")
public class BookDelServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       String id = req.getParameter("id");
       Connection con = DBUtil.getConnection();
       try{
           PreparedStatement ps =  con.prepareStatement("delete from book where id=?");
               //这里的id不能加双引号
           ps.setString(1,id);
           int num = ps.executeUpdate();
           System.out.println("删除条数="+num);
           //重定项返回页面
           resp.sendRedirect("index01");
       }catch (SQLException e){
           e.printStackTrace();
       }
    }
}
